package com.wormhole.wormholemanagement.entity;

import com.wormhole.wormholemanagement.utils.JsonConverter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
@Entity
@Table(name = "news_photos", indexes = {
        @Index(name = "idx_shooting_date", columnList = "shooting_date"),
        @Index(name = "idx_is_moved_to_archive", columnList = "is_moved_to_archive"),
        @Index(name = "idx_operator_id", columnList = "operator_id")
})
public class NewsPhoto {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "photo_id")
    private Long photoId;

    private String fileNumber;
    private String imagePath;
    private String imageName;
    private String compositeTitle;
    private String imageTitle;
    private String imageFormat;
    private String imageBackground;
    private String imageSize;
    private String imageDpi;
    private String imageScale;
    private String journalists;
    private String shootingDate;
    private String shootingPeriod;
    private String shootingLocation;
    private String eventReason;
    private String organization;
    private Boolean isMovedToArchive;
    private Long operatorId;
    private String createdAt;
    private String updatedAt;
    private Long fileSize;
    private String fileType;
    private String picIs;//图为
    @Schema(description = "形成日期")
    private String creationDate;
    /**
     * 保存期限，最大长度64字符
     */
    @Column(length = 64)
    @Schema(description = "保存期限", example = "永久")
    private String retentionPeriod;

    /**
     * 机构问题，最大长度64字符
     */
    @Column(length = 64)
    @Schema(description = "机构问题", example = "行政管理")
    private String orgIssue;

    @Convert(converter = JsonConverter.class)
    @Column(columnDefinition = "json")
    private String extendedData;

    @OneToMany(mappedBy = "photo", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<NewsPerson> persons;


    public Boolean getMovedToArchive() {
        return isMovedToArchive;
    }

    public void setMovedToArchive(Boolean movedToArchive) {
        isMovedToArchive = movedToArchive;
    }

    public void addPerson(NewsPerson person) {
        person.setPhoto(this); // 双向关联
        persons.add(person);
    }

}
